package response

import (
	"net/http"
	"quant/backend/api/dto"

	"github.com/gin-gonic/gin"
)

var (
	SuccessCode = 200 // 服务器处理成功
	FailureCode = 500 // 服务器处理出现错误
)

func Success(c *gin.Context, message string) {
	c.JSON(http.StatusOK, dto.ResponseDto{
		Code:    SuccessCode,
		Message: message,
	})
	c.Abort()
}

func SuccessWithBody(c *gin.Context, message string, data any) {
	c.JSON(http.StatusOK, dto.ResponseDto{
		Code:    SuccessCode,
		Message: message,
		Data:    data,
	})
	c.Abort()
}

func Failure(c *gin.Context, message string) {
	c.JSON(http.StatusOK, dto.ResponseDto{
		Code:    FailureCode,
		Message: message,
	})
	c.Abort()
}

func FailureWithBody(c *gin.Context, message string, body any) {
	c.JSON(http.StatusOK, dto.ResponseDto{
		Code:    FailureCode,
		Message: message,
		Data:    body,
	})
	c.Abort()
}
